package com.zzyq.pc.common.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.zzyq.pc.common.enums.LoginType;
import com.zzyq.pc.common.plugin.shiro.TokenManager;
import com.zzyq.pc.utils.EncodingUtils;
import com.zzyq.pc.utils.StringUtil;
import com.zzyq.pc.web.user.model.User;

/**
 * 控制类基类，封装一些常用方法和属性
 * 
 * @author sywd
 *
 */
public class BaseController implements CodeMsg {
    protected final Logger log = Logger.getLogger(getClass());

    protected String transString(HttpServletRequest request, String str) {
        if (StringUtils.isNotBlank(str)) {
            return EncodingUtils.fixUrlParamEncoding(request, str).replace("%", "\\%");
        }
        return str;
    }

    /**
     * 判断帐号是否为手机号
     */
    protected LoginType getLoginType(String account) {
        return StringUtil.isPhoneLegal(account) ? LoginType.Phone : LoginType.Account;
    }

    /**
     * 使用户下线(提示状态失效)
     */
    protected void unLine(HttpServletRequest httpRequest, HttpServletResponse response, User user) {
        TokenManager.logoutUser(user);
    }
}
